package com.atguigu.gmall.mq.reveiver;

import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Author: 小兰
 * @Date: 2023/5/9 18:29
 */
@Slf4j
@Component
public class DeadLetterReceiver {
    /**
     * 死信消息消费者
     */
    @RabbitListener(queues = {DeadLetterMqConfig.queue_dead_2})
    public void deadLetterMsg(String msg, Channel channel , Message message){
        try {
            if (StringUtils.isNotBlank(msg)){
                log.info("死信消费者：{}", msg);
            }
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("[xx服务]监听xxx业务异常：{}", e);


        }
    }
}
